home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Technology Seed / ADC Seed CD - July 1999.toast / Carbon SDK 1.0d10c3 / Sample Code / AppearanceSample / ProxyDialog.cp < prev    next >
Encoding:
Text File  |  1999-05-01  |  5.3 KB  |  227 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        ProxyDialog.cp
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put the technology version here xxx
  7.  
  8.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Matt Ackeret
  13.  
  14.         Other Contact:        xxx put alternate contact (ownerπs functional manager) here xxx
  15.  
  16.         Technology:            xxx put the technology group name here xxx
  17.  
  18.     Writers:
  19.  
  20.         (MAA)    Matt Ackeret
  21.  
  22.     Change History (most recent first):
  23.  
  24.          <3>      5/4/98    MAA        Remove a darn debugger() statement I left in.
  25.          <2>      3/2/98    MAA        add Assertions.h
  26.          <1>     1/29/98    MAA        First checked in.
  27. */
  28.  
  29. #include "AppearanceSamplePrefix.h"
  30.  
  31. #include <Quickdraw.h>
  32. #include <ControlDefinitions.h>
  33. #include <Dialogs.h>
  34. #include <Folders.h>
  35. #include <MacWindows.h>
  36. #include <StandardFile.h>
  37. #include <Aliases.h>
  38. #include <Errors.h>
  39. #include <Navigation.h>
  40. #include "ProxyDialog.h"
  41. //#define _DEBUG 1
  42. #include "Assertions.h"
  43.  
  44. #define kObjectProxyDialogKind    2001
  45.  
  46. static Boolean GetAFile(FSSpec *fileSpec);
  47.  
  48. void HandleProxyDrag(WindowPtr theWindow, EventRecord *event)
  49. {
  50.     if (event->modifiers & shiftKey)  // we'll do it the hard way to show you how to do it if you have special needs..
  51.         {
  52.             RgnHandle outlineRegion = NewRgn();
  53.             DragReference theDragRef;
  54.             
  55.             if (outlineRegion)
  56.                 {
  57.                     OSStatus theError;
  58.                 
  59.                     theError = BeginWindowProxyDrag(theWindow, &theDragRef, outlineRegion);
  60.                     ASSERT(theError == noErr);
  61.                     
  62.                     theError = TrackWindowProxyFromExistingDrag(theWindow, event->where, theDragRef, outlineRegion);
  63.                     ASSERT((theError == noErr) || (theError == userCanceledErr));
  64.  
  65.                     theError = EndWindowProxyDrag(theWindow, theDragRef);
  66.                     ASSERT(theError == noErr);
  67.                     
  68.                     DisposeRgn(outlineRegion);
  69.                 }
  70.         }
  71.     else // Life is simple -- let them do the work for us!!!
  72.         TrackWindowProxyDrag(theWindow, event->where);
  73. }
  74.  
  75. ProxyDialog::ProxyDialog(SInt16 resID) : BaseDialog(resID)
  76. {
  77. }
  78.  
  79. void ProxyDialog::DoDragClick(EventRecord *event)
  80. {
  81.     SInt32 ignoreMenuResult;
  82.     Boolean isPathSelect;
  83.     OSStatus pathSelectResult;
  84.     Rect        tempRect;
  85.     
  86.     isPathSelect =     IsWindowPathSelectClick(fWindow, event);
  87.  
  88.     if (isPathSelect)
  89.         pathSelectResult = WindowPathSelect(fWindow, nil, &ignoreMenuResult);
  90.  
  91.     if (!isPathSelect || (pathSelectResult == errUserWantsToDragWindow))
  92.         DragWindow( fWindow, event->where, GetRegionBounds( GetGrayRgn(), &tempRect ) );
  93. }    
  94.  
  95. ProxyDialog::~ProxyDialog()
  96. {
  97.     if ( fWindow )
  98.     {
  99.         DisposeDialog( fDialog );
  100.         fWindow = nil;
  101.     }
  102. }
  103.  
  104. static Boolean GetAFile(FSSpec *fileSpec)
  105. {
  106.     NavReplyRecord        reply;
  107.     OSErr                err;
  108.     NavDialogOptions    options;
  109.     Boolean                result = false;
  110.     
  111.     NavGetDefaultDialogOptions( &options );
  112.  
  113.     options.dialogOptionFlags &= ~kNavAllowMultipleFiles;
  114.  
  115.     err = NavGetFile( NULL, &reply, &options,
  116.                                 NULL, NULL, NULL, NULL, NULL);
  117.     
  118.     if ( (err == noErr) && reply.validRecord )
  119.     {
  120.         AEDesc        fileSpecDesc = { typeNull, nil };
  121.         AEKeyword    unusedKeyword;
  122.  
  123.         err = AEGetNthDesc( &reply.selection, 1, typeFSS, &unusedKeyword, &fileSpecDesc );
  124.  
  125.         if ( err == noErr )
  126.             AEGetDescData(&fileSpecDesc, typeFSS, fileSpec, sizeof(FSSpec) );
  127. //            BlockMoveData( *fileSpecDesc.dataHandle, fileSpec, sizeof( FSSpec ) );
  128.  
  129.         AEDisposeDesc( &fileSpecDesc );
  130.     
  131.         result = true;
  132.     }
  133.  
  134.     NavDisposeReply( &reply );
  135.  
  136.     return result;
  137. }
  138.  
  139. void ProxyDialog::UpdateContentIcon(void)
  140. {
  141.     ControlHandle theImageWell;
  142.     IconRef theIcon;
  143.     ControlButtonContentInfo myContentInfo;
  144.     OSStatus theError = noErr;
  145.     ControlContentType myType = kControlContentIconRef;
  146.  
  147.     GetDialogItemAsControl( fDialog, 5, &theImageWell);
  148.  
  149.     theError = SetControlData(theImageWell, kControlImageWellPart, kControlImageWellContentTag, sizeof(myType), (Ptr) &myType);
  150.     ASSERT(theError == noErr);
  151.  
  152.     theError = GetWindowProxyIcon(fWindow, &theIcon);
  153.  
  154.     if (theError == noErr)
  155.         {
  156.             myContentInfo.contentType = kControlContentIconRef;
  157.             myContentInfo.u.iconRef = theIcon;
  158.         
  159.             theError = SetImageWellContentInfo(theImageWell, &myContentInfo);
  160.             ASSERT(theError == noErr);
  161.         }
  162. }
  163.  
  164. void ProxyDialog::DoAddProxyIcon(Boolean fromAlias)
  165. {
  166.     FSSpec fileSpec={0,0,"\p"};
  167.     OSErr theError;
  168.     
  169.     if (GetAFile(&fileSpec))
  170.         {
  171.             if (!fromAlias)
  172.                 {
  173.                     theError = SetWindowProxyFSSpec(fWindow, &fileSpec);
  174.                     ASSERT(theError == noErr);
  175.                 }
  176.             else
  177.                 {
  178.                     AliasHandle theAlias;
  179.                 
  180.                     // In the real world you'd already have an alias.. but we're just converting
  181.                     // the FSSpec we just got *into* an alias, and using the alternate call.    
  182.                     if (NewAliasMinimal(&fileSpec,&theAlias) == noErr)
  183.                         {
  184.                             theError = SetWindowProxyAlias(fWindow,theAlias);
  185.                             ASSERT(theError == noErr);
  186.                         }
  187.                 }
  188.  
  189.             UpdateContentIcon();
  190.         }
  191. }
  192.  
  193. void
  194. ProxyDialog::HandleItemHit( short itemHit )
  195. {
  196.     OSStatus theError = noErr;
  197.     ControlHandle modifiedCheckbox;
  198.     
  199.     enum{
  200.         kRemoveProxy    = 1,
  201.         kAddFSSpec        = 2,
  202.         kAddProxyAlias    = 3,
  203.         kSetIcon        = 4,
  204.         kWindowModified = 7
  205.     };
  206.  
  207.     switch(itemHit)
  208.         {
  209.             case kRemoveProxy:
  210.                 theError = RemoveWindowProxy(fWindow);  // not exported yet
  211.                 break;
  212.             case kAddFSSpec:
  213.             case kAddProxyAlias:
  214.                 DoAddProxyIcon( itemHit == kAddProxyAlias);
  215.                 break;
  216.             case kSetIcon:
  217.                 theError = SetWindowProxyCreatorAndType(fWindow, 'ttxt','TEXT',kOnSystemDisk);
  218.                 UpdateContentIcon();
  219.                 break;
  220.             case kWindowModified:
  221.                 GetDialogItemAsControl( fDialog, kWindowModified, &modifiedCheckbox);
  222.                 SetWindowModified(fWindow,GetControlValue(modifiedCheckbox));
  223.                 break;
  224.         }
  225.     ASSERT(theError == noErr);
  226. }
  227.